package model.backup.handlers;

import database.Database;
import java.sql.SQLException;
import model.ProductFamily;
import model.backup.BackupProduct;

/**
 * Denne klasse bruges til at hente al data i bs_product og returnere det
 * @author junjie
 */
public abstract class BackupProductHandler {
    
    /**
     * Henter alle rækker i bs_product og returnerer et BackupProduct[] model
     * @return BackupProduct[]
     * @throws ClassNotFoundException
     * @throws SQLException 
     */
    public static BackupProduct[] getBackupProduct() throws ClassNotFoundException, SQLException{
        BackupProduct[] productArray = null;
        
        Database db = new Database();
        
        String[][] result = db.getFromDB("bs_product", "", "", "", 
                "id", "name", "purchasing_price", "sales_price", "szd", 
                "has_decoration", "remain_after_sale", "active", "sold", 
                "fk_product_family");
        productArray = new BackupProduct[result.length];
        
        db.closeDB();
        
         for (int i = 0; i < result.length; i++)
        {
            productArray[i] = new BackupProduct(
                            Integer.parseInt(result[i][0]), result[i][1], Double.parseDouble(result[i][2]), Double.parseDouble(result[i][3]), result[i][4], 
                            Integer.parseInt(result[i][5]), Integer.parseInt(result[i][6]), Integer.parseInt(result[i][7]), 
                            Integer.parseInt(result[i][8]), Integer.parseInt(result[i][9]));            
        }
        
        return productArray;
    }
}
